package org.daochong.fastdev.funcs;

import java.sql.SQLException;

import org.daochong.fastdev.Context;
import org.daochong.fastdev.Function;
import org.daochong.lang.StringUtils;

public class JavaFunction implements Function {

	@Override
	public boolean is(String id) {
		if (id == null)
			return false;
		return "java".equals(id) || id.startsWith("java.");
	}

	@Override
	public void exec(String key, String prop, Context context) throws SQLException {
		if (!is(key) || StringUtils.isEmpty(prop) || context == null)
			return;
		Object o = context.expression(prop);
		int pos = key.indexOf(".");
		if (pos > 0) {
			String k = key.substring(pos + 1).trim();
			if (!StringUtils.isEmpty(k)) {
				context.setAttribute(k, o);
			}
		}
	}

}
